package com.mars.admin.modules.admin;

import com.mars.admin.common.group.AddGroup;
import com.mars.admin.common.group.UpdateGroup;
import com.mars.admin.common.request.activity.ActivityCategoryRequest;
import com.mars.admin.framework.common.Result;
import com.mars.admin.modules.activity.entity.ActivityCategory;
import com.mars.admin.modules.activity.service.IActivityCategoryService;
import com.mybatisflex.core.paginate.Page;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import lombok.AllArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;


/**
 * 代码领取微信公众号【程序员Mars】
 *
 * @className: CommonController
 * @author: Mars
 * @date: 2025/7/28 22:30
 */
@Slf4j
@RestController
@RequestMapping("/admin/ActivityCategory")
@Tag(name = "后台活动类型接口", description = "后台活动类型接口")
@AllArgsConstructor
public class AdminActivityCategoryController {


    private final IActivityCategoryService activityCategoryService;


    /**
     * 新增分类
     */
    @PostMapping("/add")
    @Operation(summary = "新增活动分类", description = "新增活动分类")
    public Result<Void> add(@Validated(AddGroup.class) @RequestBody ActivityCategoryRequest request) {
        activityCategoryService.add(request);
        return Result.success();
    }


    /**
     * 更新分类
     */
    @PostMapping("/update")
    @Operation(summary = "更新活动分类", description = "更新活动分类")
    public Result<Void> update(@Validated(UpdateGroup.class) @RequestBody ActivityCategoryRequest request) {
        activityCategoryService.updateCategory(request);
        return Result.success();
    }


    /**
     * 分页查询
     */
    @PostMapping("/page")
    @Operation(summary = "分页查询活动分类", description = "分页查询活动分类")
    public Result<Page<ActivityCategory>> page(@RequestBody ActivityCategoryRequest request) {
        return Result.success(activityCategoryService.page(request));
    }

    /**
     * 删除分类
     */
    @PostMapping("/delete/{id}")
    @Operation(summary = "删除活动分类", description = "删除活动分类")
    public Result<Void> delete(@PathVariable Long id) {
        activityCategoryService.delete(id);
        return Result.success();
    }

    /**
     * 获取分类
     */
    @GetMapping("/get/{id}")
    @Operation(summary = "获取活动分类", description = "获取活动分类")
    public Result<ActivityCategory> get(@PathVariable Long id) {
        return Result.success(activityCategoryService.getById(id));
    }
}
